package com.shop.dao.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.shop.dao.CartDao;
import com.shop.domain.Cart;
import com.shop.util.MyBatisUtil;

/**
 * 
 * @author wenjuanhenxing
 * @version V1.0 CartDaoImpl.java 2016-2-10 下午8:26:26
 */
@Repository("cartDaoImpl")
public class CartDaoImpl implements CartDao {

	@Override
	public boolean addCart(Cart cart) {
		if (cart == null) {
			return false;
		}
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.insert("com.shop.dao.mapping.CartMapper"
				+ ".addCart", cart);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

	@Override
	public boolean deleteCart(Long id) {
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.delete("com.shop.dao.mapping.CartMapper"
				+ ".deleteCart", id);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

}
